<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content=" width=device-width,initial-scale=1.0">
        <link rel="stylesheet" href="css/common.css">
        <link rel="stylesheet" href="css/login.css">
        <script src="js/jquery.min.js"></script>
        <title>登录页面</title>
    </head>
    <body>
        <div class="nav">
            <span>网页聊天室</span>
            <!--使用空白元素，进行占位-->
            <div class="spaner">
                <span> </span>
            </div>
            <a href="resign.html">注册</a>
        </div>
        <div class="login-container">
          <div class="login-dialog">
              <h3>登录</h3>
              <div class="row">
                <span>用户名：</span>
                <input type="text" id="username">
               </div>
               <div class="row">
                <span>密码：</span>
                <input type="password" id="password">
              </div>
              <div class="row">
                <button id="submit" onclick="mysub()">登录</button>
              </div>
          </div>
        </div>
    </body>
    <script >
        function mysub(){
            var username=jQuery("#username");
            var password=jQuery("#password");
            if(username.val().trim()==""){
                alert("用户名不能为空");
                username.focus();
                return false;
            }
            if(password.val().trim()==""){
                alert("密码不能为空")
                password.focus();
                return false;
            }
            //根后端发消息
            jQuery.ajax({
                url:"chatRoom/login",
                type:"post",
                data:{
                    "username":username.val().trim(),
                    "password":password.val().trim()
                },
                success:function(res){
                    if(res.code!=200||res.data==null){
                        alert("登录失败"+res.msg);
                        return false;
                    }
                    if(res.code==200&&res.data.userid>0){
                        alert("登录成功");
                        location.href="client.html";
                    }
                    
                }

            });

        }
      

    </script>
</html>